package com.dd.mapper;

import com.dd.entity.Book;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface BookMapper {
    // CURD SQL方法
    // 查所有
    @Select("select * from book")
    List<Book> selectAllBooks();

    // 根据编号查图书
    @Select("select * from book where bookId = #{id}")  //
    Book selectBookById(int id);

    // 根据编号删除图书
    @Delete("delete from book where bookId = #{id}")
    int deleteBookById(int id);

    // 添加新图书
    @Insert("insert into book (bookName, bookAuthor, bookPublisher) values  (#{bookName},#{bookAuthor},#{bookPublisher})")
    int insertBook(Book book);

    // 修改图书
    @Update("update book set bookName = #{bookName}, bookAuthor=#{bookAuthor}, bookPublisher=#{bookPublisher} where bookId =#{bookId}")
    int updateBook(Book book);

    // 根据书名查询图书
    @Select("select * from book where bookName like '%${bookName}%';")  // #{} 如果是字符串，会自己加上引号，${} 只会写字符串内容，不加引号
    List<Book> selectBookByBookName(String bookName);  // bookName 与


}
